package org.apache.qpid.management.common.sasl;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.harmony.javax.security.auth.callback.Callback;
import org.apache.harmony.javax.security.auth.callback.CallbackHandler;
import org.apache.harmony.javax.security.auth.callback.NameCallback;
import org.apache.harmony.javax.security.auth.callback.PasswordCallback;
import org.apache.harmony.javax.security.auth.callback.UnsupportedCallbackException;

public class UsernameHashedPasswordCallbackHandler
  implements CallbackHandler
{
  private String user;
  private char[] pwchars;

  public UsernameHashedPasswordCallbackHandler(String paramString1, String paramString2)
    throws Exception
  {
    this.user = paramString1;
    this.pwchars = getHash(paramString2);
  }

  public void handle(Callback[] paramArrayOfCallback)
    throws IOException, UnsupportedCallbackException
  {
    for (int i = 0; i < paramArrayOfCallback.length; i++)
    {
      Object localObject;
      if ((paramArrayOfCallback[i] instanceof NameCallback))
      {
        localObject = (NameCallback)paramArrayOfCallback[i];
        ((NameCallback)localObject).setName(this.user);
      }
      else if ((paramArrayOfCallback[i] instanceof PasswordCallback))
      {
        localObject = (PasswordCallback)paramArrayOfCallback[i];
        ((PasswordCallback)localObject).setPassword(this.pwchars);
      }
      else
      {
        throw new UnsupportedCallbackException(paramArrayOfCallback[i]);
      }
    }
  }

  private void clearPassword()
  {
    if (this.pwchars != null)
    {
      for (int i = 0; i < this.pwchars.length; i++)
        this.pwchars[i] = '\000';
      this.pwchars = null;
    }
  }

  protected void finalize()
  {
    clearPassword();
  }

  public static char[] getHash(String paramString)
    throws NoSuchAlgorithmException, UnsupportedEncodingException
  {
    byte[] arrayOfByte1 = paramString.getBytes("utf-8");
    MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
    for (byte b : arrayOfByte1)
      localMessageDigest.update(b);
    byte[] arrayOfByte2 = localMessageDigest.digest();
    char[] arrayOfChar = new char[arrayOfByte2.length];
    ??? = 0;
    for (int k : arrayOfByte2)
      arrayOfChar[(???++)] = (char)k;
    return arrayOfChar;
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.apache.qpid.management.common.sasl.UsernameHashedPasswordCallbackHandler
 * JD-Core Version:    0.6.1
 */